package com.scpii.api.domain.push;

import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;

import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnore;

import com.scpii.api.common.Constants;
import com.scpii.api.common.base.FilterEntity;
import com.scpii.api.common.json.serializer.ResourceUrlSerializer;
import com.scpii.api.domain.content.Body;

public class UserMessageDevices extends FilterEntity implements Cloneable {
	@JsonIgnore
    private Long userMessageDevicesId;
    
    private Long userMessageId;
    
    private Long messageId;
    
    private Long appId;

    private String title;

    private String icon;

    private String summary;

    private List<Body> body;

    private Date startTime;

    @JsonIgnore
    private Date expireTime;

    @JsonIgnore
    private Date createTime;
    
    private Integer messageStatus;

    @JsonIgnore
    private Long userId;

    @JsonIgnore
    private Long deviceId;

    @JsonIgnore
    private String iosToken;

    private Integer intervalTime = Integer.parseInt(Constants.PUSH_INTERVAL_TIME);
    
    private static final long serialVersionUID = 1L;


	public Long getUserMessageDevicesId() {
		return userMessageDevicesId;
	}

	public void setUserMessageDevicesId(Long userMessageDevicesId) {
		this.userMessageDevicesId = userMessageDevicesId;
	}

	
	public Long getUserMessageId() {
		return userMessageId;
	}

	public void setUserMessageId(Long userMessageId) {
		this.userMessageId = userMessageId;
	}

	public Long getAppId() {
        return appId;
    }

    public void setAppId(Long appId) {
        this.appId = appId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title == null ? null : title.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
    	if(icon != null){
	    	Matcher matcher = ResourceUrlSerializer.URL_REG_PATTERN.matcher(icon);
			if (!matcher.matches()) {
				icon = StringUtils.startsWith(icon, "/") ? icon : "/" + icon;
				icon = Constants.RESOURCE_ROOT_URL + icon;
			}
    	}
        this.icon = icon == null ? null : icon.trim();
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary == null ? null : summary.trim();
    }


    public List<Body> getBody() {
		return body;
	}

	public void setBody(List<Body> body) {
		this.body = body;
	}

	public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getMessageStatus() {
        return messageStatus;
    }

    public void setMessageStatus(Integer messageStatus) {
        this.messageStatus = messageStatus;
    }

    public Long getMessageId() {
        return messageId;
    }

    public void setMessageId(Long messageId) {
        this.messageId = messageId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

  

    public Long getDeviceId() {
		return deviceId;
	}

	public void setDeviceId(Long deviceId) {
		this.deviceId = deviceId;
	}

	public String getIosToken() {
        return iosToken;
    }

    public void setIosToken(String iosToken) {
        this.iosToken = iosToken == null ? null : iosToken.trim();
    }

	public Integer getIntervalTime() {
		return intervalTime;
	}
	
	public Object clone() {
		Object o = null;
		try {
			o = (UserMessageDevices) super.clone();
		} catch (CloneNotSupportedException e) {
			System.out.println(e.toString());
		}
		return o;
	}  

}